/*******************************************************************************
 * 版权：北京润尼尔网络科技有限公司，保留所有版权<br>
 * 版本：v1.0.0<br>
 * 文件：UICompositeAceEditor.js<br>
 * 日期：2016年8月8日<br>
 * 作者: 王志远<br>
 * 功能：定义在线编程编辑器组件<br>
 * 
 * 修改记录：<br>
 * 日期 描述 更新功能<br>
 * 
 ******************************************************************************/

/**
 * @类型名称：com.rainier.easyuiex.UICompositeAceEditor<br>
 * @类型功能：组件的封装 参考https://github.com/ajaxorg/ace-builds/tree/2268d21c5893320330c9daf10b70b1973ca45eba<br>
 * @继承父类：com.rainier.easyuiex.UICompositePanel
 * @接口函数：<br>
 * 
 * init             ：构造函数
 * createComposite  ：创建Editor组件
 * getEditor        ：获取Editor
 * setTheme         ：设置外观
 * getSession       ：获取Session对象
 * setSessionMode   ：设置Session模式
 * setFontSize      ：设置字体大小
 * getLine          ：获取行数据
 * getLines         ：获取连续多行数据
 * getLength        ：获取行数
 * setValue         ：设置文本值
 * getValue         ：获取文本值
 * setReadOnly      ：设置只读模式或取消只读模式
 * 
 * @使用样例：UICompositeAceEditor.html<br>
 * 
 * 0、创建Editor组件
 * 
 * <script type="text/javascript" src="../../lib/ace/ace.js"></script>
 * 
 * //创建Shell 
 * var shell = ...;
 * 
 * //创建一个容器
 * var panelContainer = new com.rainier.easyuiex.UICompositePanel(shell,{fit:true});
 * 
 * //测试Editor
 * var editorPanel = new com.rainier.easyuiex.UICompositeAceEditor(panelContainer,{
 *     fit     :true,
 *     title   :'AceEditor',
 * });
 * 
 * 1、修改Editor外观：
 * editorPanel.setTheme("ace/theme/eclipse");
 * 
 * 2、设置Session模式：
 * editorPanel.setSessionMode("ace/mode/matlab");
 * 
 * 3、设置FontSize：
 * editorPanel.setFontSize(12);
 * 
 * 4、获取制定行数据：
 * var lineText = editorPanel.getLine(3);
 * 
 * 5、获取制定行连续数据：
 * var lineText = editorPanel.getLines(0,editorPanel.getLength()-1);
 * 
 * 6、设置文本内容
 * var value = "a=1;\nb=1;\nc=1;\nfunction r=AddFunc(v1,v2,v3)\n\tr=v1+v2+v3;\nend\nd=AddFunc(a,b,c);";
 * editorPanel.setValue(value);
 * 
 * 7、获取文本内容
 * var value = editorPanel.getValue();  
 * 
 * 8、设置只读或取消只读
 * editorPanel.setReadOnly(true); 
 * editorPanel.setReadOnly(false);
 *
 */
Rainier.UI.V2.UICompositeAceEditor = Rainier.UI.V2.UICompositePanel.extend({
    
    //定义类名称
    NAME : 'Rainier.UI.V2.UICompositeAceEditor',
    
    /**
     * 函数名称：Rainier.UI.V2.UICompositeAceEditor.init<br>
     * 函数功能：构造函数<br>
     * 参数输入：parentcom [父组件]<br>
     * 参数熟人：properties [组件属性]<br>
     * 异常信息：无<br>
     */
    init : function(parentcom,properties){   
        this._super(parentcom,properties);
    },    
    
    
    /**
     * 函数名称：Rainier.UI.V2.UICompositeTextEditor.createComposite<br>
     * 函数功能：创建组件<br>
     * 参数输入：parentcom [com.rainier.easyuiex.UIComposite] [父组件]  <br>
     * 函数返回：无<br>
     * 异常信息：无<br>
     */
    createComposite : function(parentcom) {
        var _this = this;
        this._super(parentcom);
        this.editor = ace.edit(this.getUuid());
        this.editor.setTheme("ace/theme/twilight");
        //this.editor.setTheme("ace/theme/chrome");
        this.editor.session.setMode("ace/mode/matlab");
        this.editor.setFontSize(14);
        //this.editor.setAutoScrollEditorIntoView(true);
        // this.editor.setOptions({
        //     autoScrollEditorIntoView: true,
        // });

        parentcom.on("onResize",function() {
            setTimeout( function(){
                _this.editor.resize();
            },10);
        });
     },
    
    /**
     * 函数名称：Rainier.UI.V2.UICompositeTextEditor.getEditor<br>
     * 函数功能：获取Editor组件<br>
     * 函数返回：Object<br>
     * 异常信息：无<br>
     */
    getEditor : function(){
        return this.editor;
    },
    
    /**
     * 函数名称：Rainier.UI.V2.UICompositeTextEditor.setTheme<br>
     * 函数功能：设置外观<br>
     * 参数输入：strTheme [String] [Theme名称]  <br>
     *            ace/theme/ambiance
     *            ace/theme/chaos
     *            ace/theme/chrome
     *            ace/theme/clouds
     *            ace/theme/clouds_midnight
     *            ace/theme/cobalt
     *            ace/theme/crimson_editor
     *            ace/theme/dawn
     *            ace/theme/dreamweaver
     *            ace/theme/github
     *            ace/theme/eclipse
     *            ace/theme/idle_fingers
     *            ace/theme/iplastic
     *            ace/theme/katzenmilch
     *            ace/theme/kr_theme
     *            ace/theme/kuroir
     *            ace/theme/merbivore
     *            ace/theme/merbivore_soft
     *            ace/theme/mono_industrial
     *            ace/theme/monokai
     *            ace/theme/pastel_on_dark
     *            ace/theme/solarized_dark
     *            ace/theme/solarized_light
     *            ace/theme/sqlserver
     *            ace/theme/terminal
     *            ace/theme/textmate
     *            ace/theme/tomorrow
     *            ace/theme/tomorrow_night
     *            ace/theme/tomorrow_night_blue
     *            ace/theme/tomorrow_night_bright
     *            ace/theme/tomorrow_night_eighties
     *            ace/theme/twilight
     *            ace/theme/vibrant_ink
     *            ace/theme/xcode
     *
     * 函数返回：Object<br>
     * 异常信息：无<br>
     */
    setTheme : function(strTheme){
        this.editor.setTheme(strTheme);
    },
    
    /**
     * 函数名称：Rainier.UI.V2.UICompositeTextEditor.getSession<br>
     * 函数功能：获取Editor组件<br>
     * 函数返回：object [EditorSession]<br>
     * 异常信息：无<br>
     */    
    getSession : function(){
        var editor = this.getEditor();  
        return editor.session;
    },
    
    /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.setSessionMode<br>
     * 函数功能：设置Session模式<br>
     * 参数输入：strSessionMode [String] [模式名称]  <br>
     * ace/mode/javascript
     * ace/mode/abap
     * ace/mode/abc
     * ace/mode/actionscript
     * ace/mode/ada
     * ace/mode/apache_conf
     * ace/mode/applescript
     * ace/mode/asciidoc
     * ace/mode/assembly_x86
     * ace/mode/autohotkey
     * ace/mode/batchfile
     * ace/mode/bro
     * ace/mode/c_cpp
     * ace/mode/c9search
     * ace/mode/cirru
     * ace/mode/clojure
     * ace/mode/cobol
     * ace/mode/coffee
     * ace/mode/coldfusion
     * ace/mode/csharp
     * ace/mode/css
     * ace/mode/curly
     * ace/mode/dart
     * ace/mode/diff
     * ace/mode/d
     * ace/mode/django
     * ace/mode/dockerfile
     * ace/mode/dot
     * ace/mode/drools
     * ace/mode/eiffel
     * ace/mode/ejs
     * ace/mode/elixir
     * ace/mode/elm
     * ace/mode/erlang
     * ace/mode/forth
     * ace/mode/fortran
     * ace/mode/ftl
     * ace/mode/gcode
     * ace/mode/gherkin
     * ace/mode/gitignore
     * ace/mode/glsl
     * ace/mode/gobstones
     * ace/mode/golang
     * ace/mode/groovy
     * ace/mode/haml
     * ace/mode/handlebars
     * ace/mode/haskell
     * ace/mode/haskell_cabal
     * ace/mode/haxe
     * ace/mode/hjson
     * ace/mode/html
     * ace/mode/html_elixir
     * ace/mode/html_ruby
     * ace/mode/ini
     * ace/mode/io
     * ace/mode/jack
     * ace/mode/jade
     * ace/mode/javascript
     * ace/mode/json
     * ace/mode/jsoniq
     * ace/mode/jsp
     * ace/mode/jsx
     * ace/mode/julia
     * ace/mode/kotlin
     * ace/mode/latex
     * ace/mode/lean
     * ace/mode/less
     * ace/mode/liquid
     * ace/mode/lisp
     * ace/mode/live_script
     * ace/mode/livescript
     * ace/mode/logiql
     * ace/mode/lsl
     * ace/mode/lua
     * ace/mode/luapage
     * ace/mode/lucene
     * ace/mode/makefile
     * ace/mode/markdown
     * ace/mode/mask
     * ace/mode/matlab
     * ace/mode/maze
     * ace/mode/mel
     * ace/mode/mips_assembler
     * ace/mode/mipsassembler
     * ace/mode/mushcode
     * ace/mode/mysql
     * ace/mode/nix
     * ace/mode/nsis
     * ace/mode/objectivec
     * ace/mode/ocaml
     * ace/mode/pascal
     * ace/mode/perl
     * ace/mode/pgsql
     * ace/mode/php
     * ace/mode/plain_text
     * ace/mode/powershell
     * ace/mode/praat
     * ace/mode/prolog
     * ace/mode/properties
     * ace/mode/protobuf
     * ace/mode/python
     * ace/mode/r
     * ace/mode/razor
     * ace/mode/rdoc
     * ace/mode/rhtml
     * ace/mode/rst
     * ace/mode/ruby
     * ace/mode/rust
     * ace/mode/sass
     * ace/mode/scad
     * ace/mode/scala
     * ace/mode/scheme
     * ace/mode/scss
     * ace/mode/sh
     * ace/mode/sjs
     * ace/mode/smarty
     * ace/mode/snippets
     * ace/mode/soy_template
     * ace/mode/space
     * ace/mode/sql
     * ace/mode/sqlserver
     * ace/mode/stylus
     * ace/mode/svg
     * ace/mode/swift
     * ace/mode/swig
     * ace/mode/tcl
     * ace/mode/tex
     * ace/mode/text
     * ace/mode/textile
     * ace/mode/toml
     * ace/mode/tsx
     * ace/mode/twig
     * ace/mode/typescript
     * ace/mode/vala
     * ace/mode/vbscript
     * ace/mode/velocity
     * ace/mode/verilog
     * ace/mode/vhdl
     * ace/mode/wollok
     * ace/mode/xml
     * ace/mode/xquery
     * ace/mode/yaml
     * 函数返回：无<br>
     * 异常信息：无<br>
     */        
    setSessionMode : function(strSessionMode){
        var editor = this.getEditor();  
        editor.session.setMode(strSessionMode);
    },

    /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.setFontSize<br>
     * 函数功能：设置字体大小<br>
     * 函数返回：numSize [number]<br>
     * 异常信息：无<br>
     */        
    setFontSize : function(numSize){
        var editor = this.getEditor();  
        editor.setFontSize(numSize);
    },

    /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.getLine<br>
     * 函数功能：获取行数据<br>
     * 参数输入：num [number]<br>
     * 函数返回：String
     * 异常信息：无<br>
     */      
    getLine : function(num){
        var editor = this.getEditor();  
        return editor.session.getLine(num);
    },
 
     /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.getLines<br>
     * 函数功能：制定起始和最后行号读取内容<br>
     * 参数输入：firstRow [number]<br>
     * 参数输入：lastRow  [number]<br>
     * 函数返回：Array [String]
     * 异常信息：无<br>
     */    
    getLines : function(firstRow, lastRow){
        var editor = this.getEditor();  
        return editor.session.getLines(firstRow, lastRow);
    },
    
     /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.getLength<br>
     * 函数功能：制定起始和最后行号读取内容<br>
     * 函数返回：Number [行数]
     * 异常信息：无<br>
     */   
    getLength : function(){
        var editor = this.getEditor();  
        return editor.session.getLength();
    },
    
    /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.setValue<br>
     * 函数功能：设置值Text<br>
     * 参数输入：strText [String] 文本值
     * 函数返回：无<br>
     * 异常信息：无<br>
     */       
    setValue : function(strText){
        var editor = this.getEditor();  
        return editor.session.setValue(strText);
    },
    
    /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.getValue<br>
     * 函数功能：获取文本值<br>
     * 函数返回：文本值<br>
     * 异常信息：无<br>
     */      
    getValue : function(){
        var editor = this.getEditor();  
        return editor.session.getValue();        
    },

    /**
     * 函数名称：com.rainier.easyuiex.UICompositeTextEditor.setReadOnly<br>
     * 函数功能：设置只读模式br>
     * 参数输入：readOnly [Boolean] 是否只读
     * 函数返回：无<br>
     * 异常信息：无<br>
     */         
    setReadOnly : function(readOnly){
        var editor = this.getEditor(); 
        editor.setReadOnly(readOnly);
    }
});

/**
 * UICompositeAceEditor factory method 
 * @param {Object} parentCom
 * @param {Object} properties
 */
window.Rainier.UI.V2.CreateUICompositeAceEditor = function(parentCom,properties){
    var com = new window.Rainier.UI.V2.UICompositeAceEditor(parentCom,properties);
    return com;
};